//init stuff

	YAHOO.util.Event.onDOMReady(initJS);
	
	function checkPollForm() {
		alert("sending poll");
	}
	
	function getPoll() {
		//Ajax stuff		
		$.get("polls/loadLastPoll.do", function(data){
			
			var splitted = data;
			var intitule;
			var pollId;
			var answers = new Array();
			if(splitted.indexOf("--Q--") != -1){
				//intitule = splitted.slice(5);
				splitted = splitted.slice(5);
				var index = splitted.indexOf("--ID--");
				intitule = intitule.substr(0, index);
				splitted = splitted.slice(index);
			}
			if(splitted.indexOf("--ID--") != -1){
				//intitule = splitted.slice(5);
				splitted = splitted.slice(5);
				var index = splitted.indexOf("--R--");
				pollId = intitule.substr(0, index);
				splitted = splitted.slice(index);
			}
			while (splitted.indexOf("--R--") != -1) {
				splitted = splitted.slice(5);
				if (splitted.indexOf("--R--") != -1) {
					var index = splitted.indexOf("--R--");
					answers.push(splitted.substr(0, index));
					splitted = splitted.slice(index);
				} else {
					var index = splitted.indexOf("--END--");
					answers.push(splitted.substr(0, index));
				}
			}
			var html = "";
			html += '<form name="sondageForm" id="sondageForm" action="javascript:checkPollForm()">';
			html += '<input type="hidden" name="pollId" value="'+pollId+'" />';
			html += '<div>'+intitule+'</div>';
			for (var i = 0; i < answers.length; i++) {
				html += '<input type="radio" name="responses" value="'+answers[i]+'"';
			}
			html += '<input id="sendPoll" type="submit" value="valider" />';
			html += '</form>';
			alert(html);
			$("#zoneSondage").html(table);
			
		});
	}
	
	function getPronostic() {
		//Ajax stuff		
		$.get("pronostics/loadLastEvent.do", function(data){
			
			var splitted = data;
			var intitule;
			var pollId;
			var answers = new Array();
			if(splitted.indexOf("--Q--") != -1){
				//intitule = splitted.slice(5);
				splitted = splitted.slice(5);
				var index = splitted.indexOf("--ID--");
				intitule = intitule.substr(0, index);
				splitted = splitted.slice(index);
			}
			if(splitted.indexOf("--ID--") != -1){
				//intitule = splitted.slice(5);
				splitted = splitted.slice(5);
				var index = splitted.indexOf("--R--");
				pollId = intitule.substr(0, index);
				splitted = splitted.slice(index);
			}
			while (splitted.indexOf("--R--") != -1) {
				splitted = splitted.slice(5);
				if (splitted.indexOf("--R--") != -1) {
					var index = splitted.indexOf("--R--");
					answers.push(splitted.substr(0, index));
					splitted = splitted.slice(index);
				} else {
					var index = splitted.indexOf("--END--");
					answers.push(splitted.substr(0, index));
				}
			}
			var html = "";
			html += '<form name="sondageForm" id="sondageForm" action="javascript:checkPollForm()">';
			html += '<input type="hidden" name="pollId" value="'+pollId+'" />';
			html += '<div>'+intitule+'</div>';
			for (var i = 0; i < answers.length; i++) {
				html += '<input type="radio" name="responses" value="'+answers[i]+'"';
			}
			html += '<input id="sendPoll" type="submit" value="valider" />';
			html += '</form>';
			alert(html);
			$("#zoneSondage").html(table);
			
		});
	}
	
	function initJS() {
		//alert("adazdza");
		//YAHOO.Util.Event.on("sendPoll", "click", checkPollForm);
		getPoll();
		getPronostic();
	}
	